/*
 * DprLcd.h
 *
 *  Created on: 2012-12-3
 *      Author: kylin
 */

#ifndef DPRLCD_H_
#define DPRLCD_H_

#include <QString>
#include <QMap>

enum LcdAlignment
{
	LcdAlignmentLeft=1,
	LcdAlignmentCenter=2,
	LcdAlignmentRight=3,
};

enum LcdSymbol
{
	lcdFinger=1,
	lcdArrow=2,
	lcdBlank=3,
	lcdCheckBoxChecked=4,
	lcdCheckBoxUnchecked=5,
};

class DprLcd
{
public:
	DprLcd(const QString &devNode);
	virtual ~DprLcd();

public:
	bool init();
	void close();

	void clearScreen();

	void drawText(int line,const QString &text,LcdAlignment alignment,
			bool revert);
	void drawText(int line,int indent,const QString &text,bool revert);
	void drawSymbol(int line,int indent,LcdSymbol symbol,bool revert);

	void setBackLight(bool on);

private:
	void drawTextHelper(int x,int y,const QString &text,bool revert);
	void drawOneLine(unsigned short data,unsigned char page,
			unsigned char line,unsigned char csb);

	void writeCmd(unsigned char code,unsigned char cs);
	void writeData(unsigned char data,unsigned char cs);

	bool charLatticeData(const QString &ch,QList<unsigned short> &data);
	int textLatticeWidth(const QString &text);

	static void delay(int time);

	static int charEncodingLen(char ch);

private:
	QString m_devNode;
	int m_fd;
	int m_curCtrlImage;
	int m_curDataImage;
	QMap<QString,QList<unsigned short> > m_latticeData;
};

#endif /* DPRLCD_H_ */
